package com.usooft.metaTalent.db.system.form;

import com.usooft.framework.core.query.Sort;
import com.usooft.framework.web.form.ListForm;
import com.usooft.metaTalent.core.system.query.DictItemQuery;
import java.lang.Long;
import java.lang.Override;
import java.lang.String;
import java.time.LocalDateTime;
import lombok.Setter;

@Setter
public class DictItemListForm extends ListForm<DictItemQuery> {
    private Long idIs;

    private Long[] idIn;

    private LocalDateTime createdDateOnOrBefore;

    private LocalDateTime createdDateOnOrAfter;

    private Long dictIdIs;

    private String valueContains;

    @Override
    public DictItemQuery buildQuery() {
        return DictItemQuery.builder()
                                .filter(buildFilter())
                                .sorts(buildSorts())
                                .limit(getLimit())
                                .build();
    }

    private DictItemQuery.Filter buildFilter() {
        return DictItemQuery.Filter.builder()
                .idIs(idIs)
                .idIn(idIn)
                .createdDateOnOrBefore(createdDateOnOrBefore)
                .createdDateOnOrAfter(createdDateOnOrAfter)
                .dictIdIs(dictIdIs)
                .valueContains(valueContains)
                .build();
    }

    private DictItemQuery.Sorts buildSorts() {
        DictItemQuery.Sorts.Builder builder = DictItemQuery.Sorts.builder();
        for (String sortItem : getSortItems()) {
            Sort.Order order = getSortOrder(sortItem);
            switch (sortItem) {
                case "-id", "id" -> builder.id(order);
            }
        }
        return builder.build();
    }
}
